package cn.kginglam.dynamic_excel.strategy.context;

import cn.hutool.core.util.ObjectUtil;
import cn.kginglam.dynamic_excel.model.excel.ImportModule;
import cn.kginglam.dynamic_excel.strategy.ImportExcel2DatabaseStrategy;
import cn.kginglam.dynamic_excel.strategy.param.ImportExcel2DatabaseParam;

import java.util.List;
import java.util.Objects;

/**
 * @author: Lam
 * @date: 2021-09-29 17:00
 * @description: 策略类的上下文
 */
public class ImportExcel2DatabaseContext<T extends ImportModule> {

    private ImportExcel2DatabaseStrategy importExcel2DatabaseStrategy;
    private ImportExcel2DatabaseParam importExcel2DatabaseParam;


    public ImportExcel2DatabaseContext(ImportExcel2DatabaseStrategy importExcel2DatabaseStrategy, ImportExcel2DatabaseParam importExcel2DatabaseParam) {
        this.importExcel2DatabaseStrategy = importExcel2DatabaseStrategy;
        this.importExcel2DatabaseParam = importExcel2DatabaseParam;
    }


    public void execute(List<T> importModule){
        if(ObjectUtil.isEmpty(importExcel2DatabaseParam)){
            try {
                throw new Exception("策略类需要用到的参数为空");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.importExcel2DatabaseStrategy.importExcel2Database(importModule);
    }
}
